﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Reflection;
using System.ComponentModel;

namespace etr
{

    namespace ek
    {
        enum keyPRM { r1=1,r2=2,r3=3,r44=44,r33=33,ew22=22,rrew444=444 }

        enum IceCream
        {
            [DescriptionAttribute("Chocolate Chip")]
            ChocolateChip,
            [DescriptionAttribute("Rocky Road")]
            RockyRoad,
            Vanilla
        }
        public enum Protocol
        {
            [Tag("user readable string 1")]
            Simple,
            [Tag("user readable string 2")]
            TransportApplicationCrazy,
            [Tag("user readable string 3")]
            Transparent
        }

        /*
    
    public enum Protocol
    {
        [Tag("user readable string 1")] Simple,
        [Tag("user readable string 2")] TransportApplicationCrazy,
        [Tag("user readable string 3")] Transparent
    }

            foreach (Protocol proto in System.Enum.GetValues(typeof(Protocol)))
            {
                System.Reflection.FieldInfo fieldinfo = typeof(Protocol).GetField(proto.ToString());
                object[] attr = fieldinfo.GetCustomAttributes(typeof(Tag), false);

                Tag tag = (Tag)attr[0];
                PortProtocol.Items.Add(tag.Name);
            }*/
    }
    public class EnumUtils
    {
        public static string stringValueOf(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());
            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (attributes.Length > 0)
            {
                return attributes[0].Description;
            }
            else
            {
                return value.ToString();
            }
        }

        public static object enumValueOf(string value, Type enumType)
        {
            string[] names = Enum.GetNames(enumType);
            foreach (string name in names)
            {
                if (stringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value))
                {
                    return Enum.Parse(enumType, name);
                }
            }

            throw new ArgumentException("The string is not a description or value of the specified enum.");
        }
    }
    
    
    class dic_PLP_v_1
    {
        ek.IceCream ic;

        public dic_PLP_v_1()
        {
            ic = etr.ek.IceCream.RockyRoad; 
        }
        public void mm()
        {
            //EnumUtils.stringValueOf(ic);
            functionService.shorts.m(EnumUtils.stringValueOf(ic));
        }

    }

    [System.AttributeUsage(System.AttributeTargets.Field)]
    public class Tag : System.Attribute
    {
        string name_;

        public Tag(string name)
        {
            name_ = name;
        }

        public string Name
        {
            get { return name_; }
        }
    }
















    class dic_PLP_v_0
    {
        Dictionary<int, string> d_enum;
        Dictionary<int, string> d_PLP;
        Dictionary<int, string> d_prim;
        public dic_PLP_v_0()
        {
            d_enum = new Dictionary<int, string>();
            d_prim = new Dictionary<int, string>();
            d_PLP = new Dictionary<int, string>();
        }

        public void mmm()
        {
            string[] ag = enumValueName_to_arr();
            functionService.shorts.m(ag[1]);
        }

        public string[] enumValueName_to_arr()
        {
            Type tt = typeof(ek.keyPRM);
            System.Array ar = Enum.GetValues(tt);
            string[] sa = Enum.GetNames(tt);


            int[] cip = new int[ar.Length]; int j = 0;
            foreach (object o in ar)
            {
                cip[j] = Convert.ToInt32(o); j++;
            }

            string[] vn = new string[sa.Length];
            for (int i = 0; i < sa.Length; i++)
            {
                vn[i] = string.Concat("-**",sa[i],"**",cip[i] );
            }
            return vn;
        }
    }



    class ClassTry
    {

        string s1, s2, s3;
        int q1, q2, q3;
        bool b, bb;
        public ClassTry() 
        {
            s1 = "11"; s2 = "22"; s3 = "33";
            q1 = 1; q2 = 2; q3 = 3;
            b = true; bb = false;
        }
    }
    class d2
    {
        ClassTry tr;
        public d2() 
        {
            tr = new ClassTry();
        }
        void gt()
        {
            
        }
        
        
    }
}
